package com.dylan;

import java.lang.reflect.Constructor;

class Apple {
	private String message;

	public Apple() {
		message = new String("this is an apple");
	}
	
	public Apple(String message) {
		this.message = message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void descript() {
		System.out.println(message);
	}
}

public class Hello {
	public static void main(String[] args) {
		Class<?> demo = null;
		try {
			demo = Class.forName("com.dylan.Apple");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("the class name is " + demo.getName());
		try {
			Apple o1 = (Apple) demo.newInstance();
			o1.descript();
			o1.setMessage("oh message has been changed...");
			o1.descript();
			Constructor<?>[] cons = demo.getConstructors();
			Apple o2 = (Apple) cons[1].newInstance("using parm");
			o2.descript();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		Class<?>[] intes = demo.getInterfaces();
		for(Class<?> temp : intes) {
			System.out.println(temp.getName());
		}
	}
}
